#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2025 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os

from arkcompiler_tool import run_abc


def execute_abc():
    parser = argparse.ArgumentParser()
    parser.add_argument('--arkcompiler_tool_path', help='arkcompiler tool path')
    parser.add_argument('--abc_file', help='execute abc file path')
    parser.add_argument('--module_name', help='execute abc file module name')
    parser.add_argument('--func_name', help='execute abc file function name')

    args = parser.parse_args()

    if args.module_name is None:
        args.module_name = "main"
    if args.func_name is None:
        args.func_name = "main"

    entry_point=f"{args.module_name}.ETSGLOBAL::{args.func_name}"
    arkcompiler_cmd_tool_path = os.path.join(args.arkcompiler_tool_path, 'clang_x64')
    boot_file_path = os.path.join(args.arkcompiler_tool_path, 'plugins', 'ets', 'etsstdlib.abc')
    run_abc(arkcompiler_cmd_tool_path, boot_file_path, args.abc_file, entry_point)


if __name__ == '__main__':
    execute_abc()
